package pipecleaner.agent.core;

/**
 * An ExecutableCommand instance that calls an ProcessExecutor against a executable or script 
 * on the host machine. 
 * 
 * @author J. Michael McGarr
 */
public class ExecutableCommand implements Command {

	/** The command to execute. */
	private String execution;
	
	/** Process Executor to use when executing commands. */
	private ProcessExecutor executor;
	
	/** The ouput of the command execution. */
	private Output output;

	private String name;

	/**
	 * Constructor.
	 *
	 * @param command the command string to execute on the local machine.
	 */
	public ExecutableCommand (final String command) {
		this.execution = command;
	}
	
	public ExecutableCommand (final String name, final String command) {
		this.name = name;
		this.execution = command;
	}
	
	public void execute() throws FailedCommandException {
		this.output = executor.call(execution);
	}

	public int getReturnCode() {
		return output.getReturnCode();
	}

	public String getOutput() {
		return output.getTextOutput();
	}

	/**
	 * Mutator method for the executor field.
	 *
	 * @param cExecutor to set as the new value.
	 */
	public void setExecutor(ProcessExecutor cExecutor) {
		this.executor = cExecutor;
	}

	public void setName (String name) {
		this.name = name;
	}
	
	public String getName () {
		return this.name;
	}

	public String getExecution () {
		return this.execution;
	}
}
